package com.ly.cloud.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ly.cloud.dto.XnDto;
import com.ly.cloud.dto.XnxqDto;
import com.ly.cloud.dto.XqDto;
import com.ly.cloud.service.SemesterService;
import com.ly.cloud.vo.XnVo;
import com.ly.cloud.vo.XnxqVo;
import com.ly.cloud.vo.XqVo;
import com.ly.cloud.web.utils.WebResponse;

/**
 * 学年学期Controller
 * @author caihuihai
 * @date 2018年12月11日 下午2:28:31
 */
@RestController
@RequestMapping("/semester")
public class SemesterController {
	
	@Resource
	private SemesterService semesterService;
	
	/**
	 * 查询学年列表
	 * @param xnmc 查询条件：学年名称
	 * @return
	 */
	@RequestMapping(value = "/queryXnList", method = RequestMethod.GET)
	public WebResponse<List<XnVo>> queryPageList(@RequestParam(required=false) String xnmc) {
		List<XnVo> list = semesterService.queryList(xnmc);
		return new WebResponse<List<XnVo>>().success(list);
	}
	
	/**
	 * 新增学年
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/insertXn", method = RequestMethod.POST)
	public WebResponse<Boolean> insert(@RequestHeader(required=false,value="loginUserName")String loginUserName,@RequestBody XnDto dto) {
		boolean rs = semesterService.insert(dto,loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 根据学年主键查询学年信息
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/findXnByZj/{xnzj}", method = RequestMethod.GET)
	public WebResponse<XnVo> findXnByZj(@PathVariable("xnzj") String xnzj) {
		XnVo vo = semesterService.findXnByZj(xnzj);
		return new WebResponse<XnVo>().success(vo);
	}
	
	/**
	 * 修改学年
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/updateXn", method = RequestMethod.POST)
	public WebResponse<Boolean> update(@RequestHeader(required=false,value="loginUserName")String loginUserName,@RequestBody XnDto dto) {
		boolean rs = semesterService.updateById(dto,loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 删除学年
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/deleteXn/{xnzj}", method = RequestMethod.POST)
	public WebResponse<Boolean> delete(@PathVariable("xnzj") String xnzj) {
		boolean rs = semesterService.delete(xnzj);
		return new WebResponse<Boolean>().success(rs);
	}
	
	
	/**
	 * 查询学期列表
	 * @return
	 */
	@RequestMapping(value = "/queryXqList", method = RequestMethod.GET)
	public WebResponse<List<XqVo>> queryXqList() {
		List<XqVo> list = semesterService.queryXqList();
		return new WebResponse<List<XqVo>>().success(list);
	}
	
	/**
	 * 新增学期
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/insertXq", method = RequestMethod.POST)
	public WebResponse<Boolean> insertXq(@RequestHeader(required=false,value="loginUserName")String loginUserName,@RequestBody XqDto dto) {
		boolean rs = semesterService.insertXq(dto,loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 根据学期主键查询学期信息
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/findXqByZj/{xqdm}", method = RequestMethod.GET)
	public WebResponse<XqVo> findXqByZj(@PathVariable("xqdm") String xqdm) {
		XqVo vo = semesterService.findXqByZj(xqdm);
		return new WebResponse<XqVo>().success(vo);
	}
	
	/**
	 * 修改学期
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/updateXq", method = RequestMethod.POST)
	public WebResponse<Boolean> updateXq(@RequestHeader(required=false,value="loginUserName")String loginUserName,@RequestBody XqDto dto) {
		boolean rs = semesterService.updateXq(dto,loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 删除学期
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/deleteXq/{xqdm}", method = RequestMethod.POST)
	public WebResponse<Boolean> deleteXq(@PathVariable("xqdm") String xqdm) {
		boolean rs = semesterService.deleteXq(xqdm);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 查询学年学期设置列表
	 * @return
	 */
	@RequestMapping(value = "/queryXnXqList", method = RequestMethod.GET)
	public WebResponse<List<XnxqVo>> queryXnXqList(@RequestParam(required=false) String xndm,@RequestParam(required=false) String xqdm,@RequestParam(required=false) String sfdqxq) {
		List<XnxqVo> list = semesterService.queryXnXqList(xndm,xqdm,sfdqxq);
		return new WebResponse<List<XnxqVo>>().success(list);
	}
	
	/**
	 * 获取学年list
	 * @return
	 */
	@RequestMapping(value = "/getXnList", method = RequestMethod.GET)
	public WebResponse<List<XnVo>> getXnList() {
		List<XnVo> list = semesterService.getXnList();
		return new WebResponse<List<XnVo>>().success(list);
	}
	
	/**
	 * 获取学期list
	 * @return
	 */
	@RequestMapping(value = "/getXqList", method = RequestMethod.GET)
	public WebResponse<List<XqVo>> getXqList() {
		List<XqVo> list = semesterService.getXqList();
		return new WebResponse<List<XqVo>>().success(list);
	}
	
	/**
	 * 根据学年主键和学期代码查询学年学期信息
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/findXnXqByZj/{xndm}/{xqdm}", method = RequestMethod.GET)
	public WebResponse<XnxqVo> findXnXqByZj(@PathVariable("xndm") String xndm,@PathVariable("xqdm") String xqdm) {
		XnxqVo vo = semesterService.findXnXqByZj(xndm,xqdm);
		return new WebResponse<XnxqVo>().success(vo);
	}
	
	
	/**
	 * 提交学年学期（新增和修改）
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/submitXnXq", method = RequestMethod.POST)
	public WebResponse<Boolean> submitXnXq(@RequestBody XnxqDto dto) {
		boolean rs = semesterService.submitXnXq(dto);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 删除学年学期
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/deleteXnXq/{xndm}/{xqdm}", method = RequestMethod.POST)
	public WebResponse<Boolean> deleteXnXq(@PathVariable("xndm") String xndm,@PathVariable("xqdm") String xqdm) {
		boolean rs = semesterService.deleteXnXq(xndm,xqdm);
		return new WebResponse<Boolean>().success(rs);
	}

	/**
	 * 查询学年学期的列表(通用)
	 * @return List<String>
	 * @author luhuacong
	 * @date 2018/12/27
	 */
	@RequestMapping(value = "selectXnXqListTy", method = RequestMethod.GET)
	public WebResponse<List<String>> selectXnXqListTy() {
		List<String> list = semesterService.selectXnXqListTy();
		return new WebResponse<List<String>>().success(list);
	}
}
